package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.SportService;
import com.itheima.utils.POIUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/*
类简介：

功能：

时间：2020/4/17

*/
@RestController
@RequestMapping("sport")
public class SportController {

    @Reference
    private SportService sportService;

    @RequestMapping("upload")
    public Result upload(@RequestParam("excelFile") MultipartFile excelFile){

        List<String[]> strings;

        try {
            strings = POIUtils.readExcel(excelFile);
        } catch (IOException e) {
            return new Result(false, "读取文件失败",e.getMessage());
        }

        sportService.upload(strings);

        return new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
    }

    @RequestMapping("/findPage")
    public PageResult pageQuery(@RequestBody QueryPageBean queryPageBean) {
        return sportService.findPage(queryPageBean);
    }

}
